// module.exports = function(mainApp) {
/*
 * 业务相关 services
 * @Date 2016-08-11
 */
var mainApp = angular.module("mainApp");
/****************************************app客户**********************************/
mainApp.factory("appService", ["DPUtil", "$rootScope", "$q", function(DPUtil, $rootScope, $q) {
    var _this = {
        list: function(param) {
            var defered = $q.defer();
            DPUtil.httpPost({
                method:"get",
                url: "/userSystem/client/queryByParams.do",
                data: {
                    "name": param.name,
                    "prequalification": param.prequalification,
                    "the": param.the,
                    "isPledge": param.isPledge,
                    "intoStartDate": param.intoStartDate,
                    "intoEndDate": param.intoEndDate,
                    "brandId": param.select_brand?param.select_brand.id:"",
                    "companyId": param.select_store?param.select_store.id:"",
                    "sellId": param.select_sell?param.select_sell.id:"",
                    limit:param.rows,
                    start:(param.page-1)*param.rows,
                },
                success: function(datas) {
                    defered.resolve(datas);
                }
            });
            return defered.promise;
        },
        add: function(param){
                var defered = $q.defer();
                DPUtil.httpPost({
                    url: "/userSystem/client/add.do",
                    data: {
                        requestJson:JSON.stringify({
                            id:null,
                            requestDate: param.request_date_param,
                            name: param.name,
                            // idcard: param.idcard,
                            phone: param.phone,
                            clientProperty: param.clientProperty,
                            intoWay: param.intoWay,
                            address: param.address,
                            situation: param.situation,
                            brandId: param.brandId,
                            companyId: param.companyId,
                            carId: param.carId,
                            sellId: param.sellId,
                            money: param.money,
                            periods: param.periods,
                            clientRate: param.clientRate,
                            dealerRate: param.dealerRate,
                            venderRate: param.venderRate,
                            isSurcharge: 1,
                            surchargeMoney: param.surchargeMoney,
                            surchargePeriods: param.surchargePeriods,
                            surchargeClientRate: param.surchargeClientRate,
                            surchargeDealerRate: param.surchargeDealerRate,
                            surchargeVenderRate: param.surchargeVenderRate,
                            prequalification: param.prequalification,
                            the: param.the,
                            intoDate: param.into_date_param||null,
                            loanDate: param.loan_date_param||null,
                            creditDate: param.credit_date_param||null,
                            isPledge: param.isPledge,
                            pledgeDetail: param.pledgeDetail||null,
                            contact: param.contact||null,
                            remark: param.remark||null,
                            clientPropertyName: param.clientPropertyName,
                            intoWayName: param.intoWayName,
                            situationName: param.situationName,
                            prequalificationName: param.prequalificationName,
                            theName: param.theName,
                        })  
                    },
                    success: function(datas) {
                        defered.resolve(datas);
                    }
                });
                return defered.promise;
            },
            update: function(param){
                var defered = $q.defer();
                DPUtil.httpPost({
                    url: "/userSystem/client/update.do",
                    data: {
                        requestJson:JSON.stringify({
                            id:param.id,
                            requestDate: param.request_date_param,
                            name: param.name,
                            // idcard: param.idcard,
                            phone: param.phone,
                            clientProperty: param.clientProperty,
                            intoWay: param.intoWay,
                            address: param.address,
                            situation: param.situation,
                            brandId: param.brandId,
                            companyId: param.companyId,
                            carId: param.carId,
                            sellId: param.sellId,
                            money: param.money,
                            periods: param.periods,
                            clientRate: param.clientRate,
                            dealerRate: param.dealerRate,
                            venderRate: param.venderRate,
                            isSurcharge: 1,
                            surchargeMoney: param.surchargeMoney,
                            surchargePeriods: param.surchargePeriods,
                            surchargeClientRate: param.surchargeClientRate,
                            surchargeDealerRate: param.surchargeDealerRate,
                            surchargeVenderRate: param.surchargeVenderRate,
                            prequalification: param.prequalification,
                            the: param.the,
                            intoDate: param.into_date_param||null,
                            loanDate: param.loan_date_param||null,
                            creditDate: param.credit_date_param||null,
                            isPledge: param.isPledge,
                            pledgeDetail: param.pledgeDetail||null,
                            contact: param.contact||null,
                            remark: param.remark||null,
                            createdBy:param.createdBy || "",
                            createdDate:param.createdDate || "",
                            clientPropertyName: param.clientPropertyName,
                            intoWayName: param.intoWayName,
                            situationName: param.situationName,
                            prequalificationName: param.prequalificationName,
                            theName: param.theName,
                        })
                    },
                    success: function(datas) {
                        defered.resolve(datas);
                    }
                });
                return defered.promise;
            },
        detail: function(param) {
            var defered = $q.defer();
            DPUtil.httpPost({
                method:"get",
                url: "/userSystem/client/getDetail.do",
                data: {
                    clientId:param
                },
                success: function(datas) {
                    defered.resolve(datas);
                }
            });
            return defered.promise;
        },
        item: function(param) {
            var defered = $q.defer();
            DPUtil.httpPost({
                method:"get",
                url: "/userSystem/item/query.do",
                data: {
                    requestJson:{
                        "type": param.type,
                    },
                    limit:param.rows,
                    start:(param.page-1)*param.rows,
                },
                success: function(datas) {
                    defered.resolve(datas);
                }
            });
            return defered.promise;
        },
        login: function(param) {
            var defered = $q.defer();
            DPUtil.httpPost({
                url: "/login.do",
                data: {
                    username: param.username,
                    password: param.password
                },
                success: function(datas) {
                    defered.resolve(datas);
                }
            });
            return defered.promise;
        },
        logout: function(param) {
            var defered = $q.defer();
            DPUtil.httpPost({
                url: "/logout.do",
                data: {},
                success: function(datas) {
                    defered.resolve(datas);
                }
            });
            return defered.promise;
        },
        info: function(param) {
            var defered = $q.defer();
            DPUtil.httpPost({
                url: "/has_logined.do",
                data: {},
                success: function(datas) {
                    defered.resolve(datas);
                }
            });
            return defered.promise;
        },
    };
    return _this;
}]);
var backHomeApp = mainApp; //引入pc端接口